package com.example.tabtestwithsherlock;

import android.os.Bundle;
import android.widget.Toast;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuItem;
  
public class MainActivity extends SherlockFragmentActivity  {  
    @Override  
    protected void onCreate(Bundle savedInstanceState) {  
        setTheme(R.style.Theme_Sherlock); //Used for theme switching in samples  
        super.onCreate(savedInstanceState);  
  
        ActionBar actionBar = getSupportActionBar();  
        actionBar.setTitle("ActionBar TAB");  
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);  
        actionBar.addTab(actionBar  
                .newTab()  
                .setText("처음탭")  
                .setTabListener(new TabListener<MyTab1>(this, "tab1",  
                MyTab1.class)));  
        actionBar.addTab(actionBar  
                .newTab()  
                .setText("탭2")  
                .setTabListener(new TabListener<MyTab2>(this, "tab2",  
                MyTab2.class)));  
        actionBar.addTab(actionBar  
                .newTab()  
                .setText("3번탭")  
                .setTabListener(new TabListener<MyTab3>(this, "tab3",  
                MyTab3.class)));  
  
        if (savedInstanceState != null) {  
            actionBar.setSelectedNavigationItem(savedInstanceState.getInt(  
                    "selectedTab", 0));  
        }  
    }  
      
    @Override  
    protected void onSaveInstanceState(Bundle outState) {  
        super.onSaveInstanceState(outState);  
        outState.putInt("selectedTab", getSupportActionBar()  
                .getSelectedNavigationIndex());  
    }  
  
    @Override  
    public boolean onCreateOptionsMenu(Menu menu) {  
        //Used to put dark icons on light action bar  
  
        menu.add("search")  
            .setIcon(R.drawable.ic_popup_reminder)  
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);  
  
        menu.add("Settings")  
            .setIcon(R.drawable.ic_launcher_settings)  
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);  
  
        return true;  
    }  
  
    @Override  
    public boolean onOptionsItemSelected(MenuItem item) {  
        Toast.makeText(this, "Selected Item : " + item.getTitle(),  
                Toast.LENGTH_SHORT).show();  
        return true;  
    }  
} 
